#!/usr/bin/env python
#--*-- coding: utf-8 --*--

from Tkinter import *;

# 主方法。
def main():
    app = TaskEditFrame()
    # 设置窗口标题:
    app.master.title('Hello World')
    # 主消息循环:
    app.mainloop()

# 主类
class TaskEditFrame(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master);
        self.grid(padx = 5, pady = 5);
        self.createWidgets();
        # self.bingEvents();

    def createWidgets(self):
        # 定位窗口位置。
        self.master.geometry("-0+0");
        self.name = StringVar();
        self.nameText = Entry(self, textvariable = self.name, width = 50);
        self.nameText.isDefault = True;
        self.nameText.var = self.name;
        self.nameText.grid(row = 0, column = 0);
        self.tags = StringVar();
        self.tagsText = Entry(self, textvariable = self.tags, width = 20);
        self.tagsText.isDefault = True;
        self.tagsText.var = self.tags;
        self.tagsText.grid(row = 0, column = 1);
        self.details = StringVar();
        self.detailsText = Entry(self, textvariable = self.details);
        self.detailsText.isDefault = True;
        self.detailsText.var = self.details;
        self.detailsText.grid(row = 1, column = 0, columnspan = 2, sticky=N+E+S+W);
        self.quitButton = Button(self, text='Quit', command=self.quit);
        self.quitButton.grid(row = 2, column = 0, columnspan = 2);
        self.other = StringVar();
        self.otherLabel = Label(self, text="For other.", height = 3, textvariable = self.other);
        self.otherLabel.grid(row = 5, column = 0, columnspan = 2);

        self.bind_class('Entry', '<FocusIn>', self.focusEntry);

        self.name.set("任务名称@类型");
        self.tags.set("标签");
        self.details.set("描述");
        self.nameText["fg"] = "#6d6d6d";
        self.tagsText["fg"] = "#6d6d6d";
        self.detailsText["fg"] = "#6d6d6d";

    def focusEntry(self, event):
        event.widget.var.set("");
        #self.other.set(self.nametowidget(event.widget["textvariable"]));
        #self.other.set(self.nametowidget("PY_VAR0"));

    def testEvent(self, why, when, what):
        print("Peter");
        self.other.set("peter: " + why + ", " + when + ", " + what);
        return True;

    def nameClick(self):
        self.other.set("some");

    def close(self):
        print(self.nameText.get());
        self.quit();

main();
